<template>
  <!-- 客户信息查询 v-if="roleId>=10 && roleId<=14" -->
  <Card>
	<div style="text-align:right"> 
		<!-- <Button type="primary" @click="loadResources" :loading="isLoading">导入新问卷</Button></div> -->
		<Button type="primary" @click="importModal=true" :loading="isLoading">导入新问卷</Button>		
		</div>
	
    <Table :columns="columns" :data="tableData" style="margin-top:15px">
		<template slot-scope="{ row }" slot="url">
			<a :href="row.url" target="_blank" @click="addPerson(row.id)">{{row.url}}</a>
		</template>
      <template slot-scope="{ row }" slot="operate">
		<!-- 可删除操作人为登录人的文件，其他人上传无法上传，该按钮置灰 -->
		<span v-if="true || useragentcode==row.operatorNo" class="table-button" @click="delUrl(row)">删除</span>
		<span v-else class="table-button" style="color:#ccc">删除</span>
        <span v-if="roleId!=21" class="table-button" @click="getPeopleData(row)" style="margin-left: 10px;">查看已点击人员</span>
      </template>
    </Table>

    <Page :total="ipagination.total" show-sizer show-total style="text-align:right;margin-top:20px"
      @on-change="handleCurrentChange" @on-page-size-change="handleSizeChange"
      :page-size-opts="ipagination.pageSizeOptions" :current="ipagination.pageIndex" :page-size="ipagination.pageSize"
      transfer></Page>

	  <Modal title="导入新问卷" v-model="importModal" :mask-closable="false">
      <Input v-model="url" clearable
        placeholder="请输入问卷地址" />
      <template #footer>
        <Button @click="importModal=false;url=''" style="margin-right:10px;">取消</Button>
        <Button type="primary" @click="replyModalSubmit" :loading="modalLoading">确定</Button>
      </template>
    </Modal>
	<exam-people ref="peopleModal"></exam-people>

  </Card>
</template>

<script>
import { loadResourcesMixin } from "../../util/mixins/loadResourcesMixin";
import { tableChangeMixin } from "../../util/mixins/tableChangeMixin";
import ExamPeople from "./components/examPeople.vue"
export default {
  name: "clientInfo",
  mixins: [loadResourcesMixin, tableChangeMixin],
  components:{ExamPeople},
  data() {
    return {
      mixinData: {
        tableAxios: "examinationmanagementGetList",
      },  
	  url:'',
	  roleId:'',
	  useragentcode:'',
	  importModal:false,
	  modalLoading:false,   
	//   peopleModal:false,
	//   peopleData:[], 
      columns: [
        {
          title: "序号",
          type: "index",
          align: "center",
		  width:80
        },        
		{
          title: "问卷地址",
          key: "url",
		   slot: "url",
          align: "center",
        },
        {
          title: "上传时间",
          key: "createTime",
          align: "center",
        },
		{
          title: "操作人",
          key: "operatorName",
          align: "center",
		  width:120
        },
		{
          title: "操作",
          key: "operate",
		  slot: "operate",
          align: "center",
          width: "200",
          fixed: "right",
        },
      ],
    };
  },
  mounted() {
	this.useragentcode=sessionStorage.getItem('useragentcode')
	this.roleId=sessionStorage.getItem('roleId')
  },
  methods: {
	addPerson(id){
		this.apiB.addPerson({id:id})
	},
	replyModalSubmit(){
		if(!this.url){
			this.$Message.info("请输入问卷地址")
			return
		}
		this.apiB.examinationmanagementUpload({url:this.url}).then(res=>{
			this.$Message.info(res.msg)
			if (res.code == 200){
				this.loadResources()
				this.importModal=false
				this.url=""
			}
		})
	},
	getPeopleData(row){
		// this.peopleData=[]
		// this.apiB.examinationmanagementUpload({url:this.url}).then(res=>{
		// 	if (res.code == 200){
		// 		this.peopleData=res.data				
		// 	}else{
		// 		this.$Message.info(res.msg)
		// 	}
		// })
		this.$refs.peopleModal.getPeopleData(row)
	},
	delUrl(row){
		this.$Modal.confirm({
			title:"确定要删除吗",
			onOk: () => {
          		//点击确认的方法          
				this.apiB.examinationmanagementDelete({ id: row.id,operatorNo:row.operatorNo }).then(res => {
				//console.log(res);
				if (res.code === 200) {
					this.$Message.success("问卷已删除成功");
					this.loadResources()
				} else {
					this.$Message.info(res.msg);
				}
			});
		},
		})
	}
	
  },
};
</script>